import 'package:hive/hive.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:zywz/models/user_company.dart';

part 'user.g.dart';

@HiveType(typeId: 1)
@JsonSerializable()
class User {
  @HiveField(0)
  final String? id;

  @HiveField(1)
  final String? gmtCreate;

  @HiveField(2)
  final String? gmtModified;

  @HiveField(3)
  final String? phone;

  @HiveField(4)
  final String? reference;

  @HiveField(5)
  final String? referenceCompany;

  @HiveField(6)
  final String? registerTime;

  @HiveField(7)
  final String? companyId;

  @HiveField(8)
  AppCompanyDto? appCompanyDto;

  User({
    this.id,
    this.gmtCreate,
    this.gmtModified,
    this.phone,
    this.reference,
    this.referenceCompany,
    this.registerTime,
    this.companyId,
    this.appCompanyDto,
  });

  factory User.fromJson(Map<String, dynamic> json) {
    return User(
      id: json['id']?.toString(),
      gmtCreate: json['gmtCreate']?.toString(),
      gmtModified: json['gmtModified']?.toString(),
      phone: json['phone']?.toString(),
      reference: json['reference']?.toString(),
      referenceCompany: json['referenceCompany']?.toString(),
      registerTime: json['registerTime']?.toString(),
      companyId: json['companyId']?.toString(),
      appCompanyDto: json['appCompanyDto'] != null
          ? AppCompanyDto.fromJson(json['appCompanyDto'] as Map<String, dynamic>)
          : null,
    );
  }

  Map<String, dynamic> toJson() => _$UserToJson(this);
}